cmake_minimum_required( VERSION 3.2 )
project( quarkts-cpp
         VERSION 1.7.9
         DESCRIPTION "An open-source OS for small embedded applications"
         LANGUAGES CXX )

# Create static library
add_library( ${PROJECT_NAME} STATIC
             "${CMAKE_CURRENT_LIST_DIR}/critical.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/list.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/clock.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/timer.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/queue.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/task.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/prioqueue.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/kernel.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/fsm.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/coroutine.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/util.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/cli.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/memory.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/bytebuffer.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/response.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/input.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/logger.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/job.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/job_manager.cpp"
             "${CMAKE_CURRENT_LIST_DIR}/security_config.cpp"
           )

# Set output directory for static library
set_target_properties( ${PROJECT_NAME} PROPERTIES
    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
)

# Compiler options for static library
target_compile_options( ${PROJECT_NAME} PRIVATE
           $<$<COMPILE_LANGUAGE:CXX>:
               -std=c++11 -Wall -Wextra -Wpedantic -Wconversion
               -flto -Wimplicit-fallthrough=0 -Wformat-security
               -Wduplicated-cond -Wfloat-equal -Wshadow -Wsign-conversion
               -Wlogical-not-parentheses -Wnull-dereference  -Wstringop-overflow
               -fdump-rtl-expand -fstrict-aliasing  -Wstrict-aliasing
               -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs
               -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wshadow
               -Wwrite-strings -Wsign-compare  -Wmissing-declarations -Wformat
               -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked
               -Wredundant-decls -Wunreachable-code
            >
)

# Include directories
target_include_directories( ${PROJECT_NAME} PUBLIC
    ${PROJECT_SOURCE_DIR}
    ${PROJECT_SOURCE_DIR}/include
)

# Create interface library for header-only usage
add_library( ${PROJECT_NAME}-interface INTERFACE )
target_include_directories( ${PROJECT_NAME}-interface INTERFACE ${PROJECT_SOURCE_DIR} )

# Install targets
install(TARGETS ${PROJECT_NAME}
        ARCHIVE DESTINATION lib
        LIBRARY DESTINATION lib
        RUNTIME DESTINATION bin)

install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
        DESTINATION include
        FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h")
